﻿var page = {
    pix: 50,
    moveX: 80,
    moveY: 50,

    branchList: [
        { name: "video", xStart: 0, yStart: 0, x: 63, y: 20 },
        { name: "wifi", xStart: 0, yStart: 0, x: 30, y: 77 },
        { name: "MQTT", xStart: 0, yStart: 0, x: 30, y: 141 },
        { name: "mymusic", xStart: 0, yStart: 0, x: 63, y: 197 },

        { name: "weather", xStart: 430, yStart: 0, x: 368, y: 20 },
        { name: "calendar", xStart: 430, yStart: 0, x: 401, y: 77 },
        { name: "user", xStart: 430, yStart: 0, x: 401, y: 141 },
        { name: "home", xStart: 430, yStart: 0, x: 368, y: 197 },
    ],
    indexEnter: 0,

    /* 此方法在第一次显示窗体前发生 */
    onLoad: function (event) {
        audio.stop();
        refreshDate(this);          //获取信号质量--app.js
        main_Setting_page = this;   //设置该Page的值 ----app.js----

        for (var i = 0; i < 8; i++) {
            if (i < 4) {
                this.branchList[i].x += this.pix;
            }
            else {
                this.branchList[i].x -= this.pix;
            }
        }
    },

    /*控件跟随进入的动画*/
    iconEnter: function () {
        //修改使用新的动画
        var thiz = this;

        thiz.isShow = !thiz.isShow;  //显示的标志
        var data = new Object();     //创建一个 Object 对象 data
        if (!thiz.isShow) {
            console.log("hide = > true");
            this.setData(data);
        }
        var date = new Date();
        var anim = pm.createAnimator(200, 20);
        anim.duration(200).direction('normal').timing('ease-in').interpolator('linear');

        for (thiz.indexEnter = 0; thiz.indexEnter < 4; thiz.indexEnter++) {
            if (thiz.isShow) //进入动画
            {
                var branch1 = thiz.branchList[thiz.indexEnter];
                var branch2 = thiz.branchList[4 + thiz.indexEnter];
                //添加新动画
                anim.bind(branch1.name);

                var getrectX = this.getData('wifi', 'rect').x;
                var getrectX1 = this.getData('calendar', 'rect').x;

                anim.translateX(60 - getrectX);
                anim.bind(branch2.name);

                anim.translateX(370 - getrectX1);

                var data1 = new Object();
                data1[branch1.name] = { hide: false };
                data1[branch2.name] = { hide: false };
                this.setData(data1);
            }
            else {  //退出动画
                var branch1 = thiz.branchList[3 - thiz.indexEnter];
                var branch2 = thiz.branchList[7 - thiz.indexEnter];
                //添加新动画
                var getrectX = this.getData('wifi', 'rect').x;
                var getrectX1 = this.getData('calendar', 'rect').x;
                anim.bind(branch1.name);
                anim.translateX(-94 - getrectX);
                anim.bind(branch2.name);
                anim.translateX(524 - getrectX1);
            }
        }
        anim.start();
    },

    /* 此方法展示窗体后发生 */
    onResume: function (event) {

    },

    /* 当前页状态变化为显示时触发 */
    onShow: function (event) {

    },

    /* 当前页状态变化为隐藏时触发 */
    onHide: function (event) {

    },

    /* 此方法关闭窗体前发生 */
    onExit: function (event) {
        clearInterval(this.dateTimer);//app.js中定时器--刷新网络信号
        audio.stop();
    },

    onBranch: function (event) {
        this.iconEnter();
    },

    onBtn: function (event) {
        pm.navigateTo(event.target.id + "/" + event.target.id);
    },
};

Page(page);

page = 0;
